// cramming bits into a struct
struct WeirdData {
	int a : 5;			// this syntax only works in a struct
	unsigned int b : 6;
	int c : 6;
	int d : 6;
	int e : 2;
	int flag1 : 1;
	int flag2 : 1;
	int flag3 : 1;
	int flag4 : 1;
	int flag5 : 1;
	int flag6 : 2;
};
struct TINYCHARS
{
	char one, two, three;
};
union NUMBER
{
	int a;	char b;	short c;	TINYCHARS d;	WeirdData w;
};

void bitCraziness()
{
	// test the union...
	NUMBER n;
	n.a = 0;
	n.d.two = 1;
	printf("a:%d   b:%d   c:%d   d.1:%d  d.2:%d  d.3:%d\n"
		"%d %d %d %d %d %d %d %d %d %d %d\n", 
		n.a, n.b, n.c, n.d.one, n.d.two, n.d.three,
		n.w.a, n.w.b, n.w.c, n.w.d, n.w.e, 
		n.w.flag1, n.w.flag2, n.w.flag3, n.w.flag4,
		n.w.flag5, n.w.flag6);

	// do the same thing as the union above... 
	// but with less inderaction
	int a = 0;
	((TINYCHARS*)&a)->two = 1;
	printf("a:%d\n", a);

	printf("sizeof WeirdData:%d\n", sizeof(WeirdData));

	// uncomment this code to see an infinite loop. w.b is only 6 bits, and will never reach 100
//	WeirdData w;
//	for(w.b = 0; w.b < 100; ++w.b)
//		printf("%d ", w.b);

	// wait before doing the actual program
	getch();
}